home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2008 February / PC_Format_022008.iso / Internet / Mozilla Thunderbird wtyczki / lightning-0.7-tb-win.xpi / components / calWcapCalendarModule.js < prev    next >
Encoding:
Text File  |  2007-09-19  |  8.9 KB  |  223 lines

  1. /* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Sun Microsystems code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Sun Microsystems, Inc.
  19.  * Portions created by the Initial Developer are Copyright (C) 2007
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Daniel Boelzle <daniel.boelzle@sun.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. //
  40. // init code for globals, prefs:
  41. //
  42.  
  43. // constants:
  44. const NS_OK = Components.results.NS_OK;
  45. const nsIException = Components.interfaces.nsIException;
  46. const nsISupports = Components.interfaces.nsISupports;
  47. const calIWcapSession = Components.interfaces.calIWcapSession;
  48. const calIWcapCalendar = Components.interfaces.calIWcapCalendar;
  49. const calIWcapErrors = Components.interfaces.calIWcapErrors;
  50. const calICalendar = Components.interfaces.calICalendar;
  51. const calIItemBase = Components.interfaces.calIItemBase;
  52. const calIOperationListener = Components.interfaces.calIOperationListener;
  53. const calIFreeBusyProvider = Components.interfaces.calIFreeBusyProvider;
  54. const calIFreeBusyInterval = Components.interfaces.calIFreeBusyInterval;
  55. const calIErrors = Components.interfaces.calIErrors;
  56.  
  57. // ctors:
  58. var CalEvent;
  59. var CalTodo;
  60. var CalDateTime;
  61. var CalDuration;
  62. var CalPeriod;
  63. var Timer;
  64.  
  65. // some string resources:
  66. var g_privateItemTitle;
  67. var g_confidentialItemTitle;
  68. var g_busyItemTitle;
  69. var g_busyPhantomItemUuidPrefix;
  70.  
  71. // global preferences:
  72.  
  73. // caching the last data retrievals:
  74. var CACHE_LAST_RESULTS = 4;
  75. // timer secs for invalidation:
  76. var CACHE_LAST_RESULTS_INVALIDATE = 120;
  77.  
  78. // logging:
  79. var LOG_LEVEL = 0;
  80.  
  81. // whether alarms are turned on/off:
  82. var SUPPRESS_ALARMS = false;
  83.  
  84. var g_ioService = null;
  85. function getIoService() {
  86.     if (!g_ioService) {
  87.         g_ioService = Components.classes["@mozilla.org/network/io-service;1"]
  88.                       .getService(Components.interfaces.nsIIOService);
  89.     }
  90.     return g_ioService;
  91. }
  92.  
  93. function initWcapProvider()
  94. {
  95.     try {
  96.         // xxx todo: hack
  97.         // the master password prompt is currently not guarded against
  98.         // multiple prompt; this initializes/raises the pw db at early stage.
  99.         var passwordManager = Components.classes["@mozilla.org/passwordmanager;1"]
  100.                                         .getService(Components.interfaces.nsIPasswordManager);
  101.         var enumerator = passwordManager.enumerator;
  102.         if (enumerator.hasMoreElements())
  103.             enumerator.getNext(); // actually prompts...
  104.     }
  105.     catch (exc) {
  106.     }
  107.     
  108.     try {        
  109.         // ctors:
  110.         CalEvent = new Components.Constructor("@mozilla.org/calendar/event;1",
  111.                                               "calIEvent");
  112.         CalTodo = new Components.Constructor("@mozilla.org/calendar/todo;1",
  113.                                              "calITodo");
  114.         CalDateTime = new Components.Constructor("@mozilla.org/calendar/datetime;1",
  115.                                                  "calIDateTime");
  116.         CalDuration = new Components.Constructor("@mozilla.org/calendar/duration;1",
  117.                                                  "calIDuration");
  118.         CalPeriod = new Components.Constructor("@mozilla.org/calendar/period;1",
  119.                                                "calIPeriod");
  120.         Timer = new Components.Constructor("@mozilla.org/timer;1",
  121.                                            "nsITimer");
  122.         
  123.         initLogging();
  124.         
  125.         // some string resources:
  126.         g_privateItemTitle = calGetString("wcap", "privateItem.title.text");
  127.         g_confidentialItemTitle = calGetString("wcap", "confidentialItem.title.text");
  128.         g_busyItemTitle = calGetString("wcap", "busyItem.title.text");
  129.         g_busyPhantomItemUuidPrefix = ("PHANTOM_uuid_" + getUUID());
  130.  
  131.         SUPPRESS_ALARMS = getPref("calendar.wcap.suppress_alarms", true);
  132.  
  133.         CACHE_LAST_RESULTS = getPref("calendar.wcap.cache_last_results", 4);
  134.         CACHE_LAST_RESULTS_INVALIDATE = getPref("calendar.wcap.cache_last_results_invalidate", 120);
  135.     }
  136.     catch (exc) {
  137.         logError(exc, "error in init sequence");
  138.     }
  139. }
  140.  
  141. var calWcapCalendarFactory = { // nsIFactory:
  142.     lockFactory: function calWcapCalendarFactory_lockFactory(lock) {},
  143.     
  144.     createInstance: function calWcapCalendarFactory_createInstance(outer, iid) {
  145.         if (outer)
  146.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  147.         return (new calWcapCalendar()).QueryInterface(iid);
  148.     }
  149. };
  150.  
  151. var calWcapCalendarModule = { // nsIModule:
  152.     
  153.     WcapCalendarInfo: {
  154.         classDescription: "Sun Java System Calendar Server WCAP Provider",
  155.         contractID: "@mozilla.org/calendar/calendar;1?type=wcap",
  156.         classID: Components.ID("{CF4D93E5-AF79-451a-95F3-109055B32EF0}")
  157.     },
  158.     
  159.     WcapSessionInfo: {
  160.         classDescription: "Sun Java System Calendar Server WCAP Session",
  161.         contractID: "@mozilla.org/calendar/wcap/session;1",
  162.         classID: Components.ID("{CBF803FD-4469-4999-AE39-367AF1C7B077}")
  163.     },
  164.     
  165.     registerSelf: function calWcapCalendarModule_registerSelf(compMgr, fileSpec, location, type)
  166.     {
  167.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  168.         compMgr.registerFactoryLocation(this.WcapCalendarInfo.classID,
  169.                                         this.WcapCalendarInfo.classDescription,
  170.                                         this.WcapCalendarInfo.contractID,
  171.                                         fileSpec, location, type);
  172.         compMgr.registerFactoryLocation(this.WcapSessionInfo.classID,
  173.                                         this.WcapSessionInfo.classDescription,
  174.                                         this.WcapSessionInfo.contractID,
  175.                                         fileSpec, location, type);
  176.     },
  177.     
  178.     unregisterSelf: function calWcapCalendarModule_unregisterSelf(compMgr, fileSpec, location)
  179.     {
  180.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  181.         compMgr.unregisterFactoryLocation(this.WcapCalendarInfo.classID, fileSpec);
  182.         compMgr.unregisterFactoryLocation(this.WcapSessionInfo.classID, fileSpec);
  183.     },
  184.     
  185.     m_scriptsLoaded: false,
  186.     getClassObject: function calWcapCalendarModule_getClassObject(compMgr, cid, iid)
  187.     {
  188.         if (!this.m_scriptsLoaded) {
  189.             // loading extra scripts from ../js:
  190.             const scripts = [ "calUtils.js", "calWcapUtils.js", "calWcapErrors.js",
  191.                               "calWcapRequest.js", "calWcapSession.js",
  192.                               "calWcapCalendar.js", "calWcapCalendarItems.js" ];
  193.             var scriptLoader =
  194.                 Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  195.                           .createInstance(Components.interfaces.mozIJSSubScriptLoader);
  196.             var ioService = getIoService();
  197.             var baseDir = __LOCATION__.parent.parent;
  198.             baseDir.append("js");
  199.             for each (var script in scripts) {
  200.                 var scriptFile = baseDir.clone();
  201.                 scriptFile.append(script);
  202.                 scriptLoader.loadSubScript(ioService.newFileURI(scriptFile).spec, null);
  203.             }
  204.             initWcapProvider();
  205.             this.m_scriptsLoaded = true;
  206.         }
  207.         
  208.         if (!iid.equals(Components.interfaces.nsIFactory))
  209.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  210.         if (!cid.equals(calWcapCalendar.prototype.classID))
  211.             throw Components.results.NS_ERROR_NO_INTERFACE;
  212.         return calWcapCalendarFactory;
  213.     },
  214.     
  215.     canUnload: function calWcapCalendarModule_canUnload(compMgr) { return true; }
  216. };
  217.  
  218. /** module export */
  219. function NSGetModule(compMgr, fileSpec) {
  220.     return calWcapCalendarModule;
  221. }
  222.  
  223.